package com.hr.mapper;

import com.hr.domain.dto.UserFavoriteDTO;
import com.hr.domain.po.Favorite;
import com.hr.domain.vo.FavoriteVO;
import com.hr.domain.vo.UserFavoriteVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 86150
 * @description 针对表【favorite(用户收藏表)】的数据库操作Mapper
 * @createDate 2025-11-11 10:48:12
 * @Entity com.hr.domain.po.Favorite
 */
@Mapper
public interface FavoriteMapper {

    /**
     * 添加收藏
     * @param houseId 房源ID
     * @param userId 用户ID
     * @return 是否添加成功
     */
    @Insert("insert into favorite(house_id, user_id) values(#{houseId}, #{userId})")
    int addFavorite(Long houseId, Long userId);

    /**
     * 取消收藏
     * @param houseId 房源ID
     * @param userId 用户ID
     * @return 是否取消成功
     */
    @Delete("delete from favorite where house_id = #{houseId} and user_id = #{userId}")
    int cancelFavorite(Long houseId, Long userId);

    /**
     * 获取收藏列表
     * @return 收藏列表
     */
    List<FavoriteVO> selectFavoriteList();

    /**
     * 判断用户是否收藏了此房源
     * @param userId 用户ID
     * @param houseId 房源ID
     * @return 是否收藏
     */
    @Select("select * from favorite where house_id = #{houseId} and user_id = #{userId}")
    Boolean isUserCollectedHouse(Long userId, Long houseId);

    /**
     * 根据用户ID和房源ID查询收藏记录
     * @param userId 用户ID
     * @param houseId 房源ID
     * @return 收藏记录
     */
    @Select("select * from favorite where user_id = #{userId} and house_id = #{houseId}")
    Favorite findByUserIdAndHouseId(Long userId, Long houseId);


    List<UserFavoriteVO> selectByUserId(UserFavoriteDTO userFavoriteDTO);
}



